// 获取随机的六位数字验证码
exports.getVerificationCode = () => {
    let code = '';
    for (var i = 0; i < 6; i++) {
        code += Math.floor(Math.random() * 10);
    }
    return code
}

// 获取随机的16位数字
exports.getRandom16DigitNumber = () => {
    let code = '';
    for (var i = 0; i < 16; i++) {
        code += Math.floor(Math.random() * 10);
    }
    return code
}

// 获取当前系统时间
exports.getCurrentTime = (type) => {
    let date = new Date()
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    let day = date.getDate()
    let hour = date.getHours()
    let min = date.getMinutes()
    let sec = date.getSeconds()
    hour = hour > 9 ? hour : `0${ hour }`
    min = min > 9 ? min : `0${ min }`
    sec = sec > 9 ? sec : `0${ sec }`
    if(type == 'date') return `${ year }/${ month }/${ day }` 
    else return `${ year }/${ month }/${ day } ${ hour }:${ min }:${ sec }`
}

// 计算时间差
exports.calculationTime = (time) => {
    let currentTime = new Date()
    let oldTime = new Date(Date.parse(time))
    let timeDiff = currentTime.getTime() - oldTime.getTime()
    let timeInterval = Math.floor(timeDiff/1000/60)
    return timeInterval
}

// 计算二十四节气
exports.calculateSolarTerm = (yyyy,mm,dd) => {
    mm = mm-1
    let sTermInfo = new Array(0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758)
    let solarTerm = new Array('小寒','大寒','立春','雨水','惊蛰','春分','清明','谷雨','立夏','小满','芒种','夏至','小暑','大暑','立秋','处暑','白露','秋分','寒露','霜降','立冬','小雪','大雪','冬至')
    let solarTerms = ''
    //　　此方法可以获取该日期处于某节气
    while (solarTerms == ''){ 
        let tmp1 = new Date((31556925974.7 * (yyyy - 1900) + sTermInfo[mm * 2 + 1] * 60000) + Date.UTC(1900, 0, 6, 2, 5))
        let tmp2 = tmp1.getUTCDate()
        if (tmp2 == dd) solarTerms = solarTerm[mm * 2 + 1]
        tmp1 = new Date((31556925974.7 * (yyyy - 1900) + sTermInfo[mm * 2] * 60000) + Date.UTC(1900, 0, 6, 2, 5))
        tmp2 = tmp1.getUTCDate()
        if (tmp2 == dd) solarTerms = solarTerm[mm * 2]
        if(dd > 1) {
            dd = dd - 1 
        } else {
            mm = mm - 1
            if(mm < 0){ 
                yyyy = yyyy - 1
                mm = 11
            } 
            dd = 31 
        } 
    } 
    return solarTerms 
}

// 计算当前季节
// 正月、二月、三月、四月、五月、六月、七月、八月、九月、十月、十一月、十二月
exports.calculateCurrentSeason = () => {
    let date = new Date()
    let month = date.getUTCMonth()
    console.log('month', month)
    let monthArr = ['正月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
    return monthArr[month]
}